home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: vandevod@cs.rpi.edu (David Vandevoorde)
- Newsgroups: comp.std.c++
- Subject: Re: Syntax for template instantiation and specialization
- Date: 03 Apr 1996 09:23:04 PST
- Organization: RPI Computer Science
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <xsok9zx1f0b.fsf@avs.cs.rpi.edu>
- References: <4jr0ur$bdh@wn1.sci.kun.nl>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: 03 Apr 1996 10:52:36 -0500
- In-Reply-To: Marian Hellema's message of 02 Apr 96 13:34:59 GMT
- X-Newsreader: Gnus v5.1
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMWKz+Uy4NqrwXLNJAQGWdAH+K5LOm3kMswWOxfv9ok5wudyw+7m53Adb
- 6neHlqQ+RwthR6O5q/QR28KOfLhY87g7Ze+/3sCekM0lkPSN589OkQ==
- =DZZW
- Originator: austern@isolde.mti.sgi.com
-
- >>>>> "MH" == Marian Hellema <marian@atcmp.nl> writes:
- MH> What is the correct syntax for template instantiation and
- MH> specialization?
-
- MH> From my copy of the DWP April 95 I gather:
-
- This has changed somewhat since then...
-
- MH> template<class T>
- MH> T max(T a, T b) { return a>b?a:b; }
-
- MH> template int max<int>(int, int); //instantiation
- MH> /* OR: */
- MH> template int max<>(int, int); //instantiation
-
- (or you can leave out the `<>', I think).
-
- MH> const char* max<const char*>max(const char* a, const char* b)
- MH> { /* specialization */ }
-
- Should now be:
-
- template<> // <- note this!
- char const*
- max<char const*>(char const*, char const*) // ...
-
- MH> const char* max<>(const char* a, const char* b)
- MH> { /* specialization */ }
-
- Same thing...
-
- template<> // <- note this!
- char const*
- max(char const*, char const*) // ...
-
- should be OK. I believe `max<>' would be fine too.
- (I'm deducing this from _examples_ in a not-yet-WP rework of the
- templates-chapter; I could very well be very wrong).
-
- [...]
- MH> 2. Is the following still legal:
- MH> int max(int, int); //instantiation??
-
- It is still legal and I believe this is what would be called a
- ``guiding function declaration''. Without the guiding declaration
-
- max('a', 100);
-
- would not find a match (because conversions are not considered when
- matching template arguments); _with_ the guiding declaration, the
- regular overloading rules (possibly involving implicit conversions)
- apply.
-
- Daveed
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-